package com.zerui.manager.app.openplan.executer;

import com.alibaba.cola.catchlog.CatchAndLog;
import com.alibaba.cola.exception.BizException;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.zerui.cola.dto.Response;
import com.zerui.manager.openplan.OpenPlan;
import com.zerui.manager.openplan.gateway.OpenPlanGateWay;
import com.zerui.manager.web.cmd.OpenPlanUpdateCmd;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @Author wh
 * @create_time 2023-09-02 9:43
 */
@Component
@CatchAndLog
public class OpenPlanUpdateCmdExe {

    @Resource
    private OpenPlanGateWay openPlanGateWay;

    public Response execute(OpenPlanUpdateCmd cmd) {
        OpenPlan openPlan = openPlanGateWay.selectById(cmd.getId());
        if(ObjectUtils.isEmpty(openPlan)){
            throw new BizException("开门计划不存在");
        }
        if(openPlan.getAccept()){
            throw new BizException("开门计划已生效不能修改");
        }
        openPlan.update(cmd.getName(), cmd.getStartDate(), cmd.getEndDate(),
                cmd.getStartTime(), cmd.getEndTime(), cmd.getWeekend(), cmd.getRemark());
        return openPlanGateWay.updateById(openPlan);
    }
}
